package com.ruoyi.common.dao.service;

import com.ruoyi.common.core.domain.WorkerNodeEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface SysWorkerNodeDao extends SysBaseDao<WorkerNodeEntity,Long>, CrudRepository<WorkerNodeEntity,Long> {

    @Query(value = "select * from worker_node where HOST_NAME=:host and port=:port",nativeQuery = true)
    WorkerNodeEntity getWorkerNodeByHostPort(@Param("host") String host, @Param("port") String port);

    @Query(value = "insert into worker_node(ID, HOST_NAME, PORT, TYPE, LAUNCH_DATE, MODIFIED, CREATED)values(:#{#workerNodeEntity.id},:#{#workerNodeEntity.hostName},:#{#workerNodeEntity.port},:#{#workerNodeEntity.type},:#{#workerNodeEntity.launchDate},:#{#workerNodeEntity.modified},:#{#workerNodeEntity.created})",nativeQuery = true)
    @Modifying
    @Transactional
    void addWorkerNode(@Param("workerNodeEntity") WorkerNodeEntity workerNodeEntity);
}
